package cn.hfatec.shms.web.qz.qzActual.action;

import cn.hfatec.shms.web.cw.cwChtb.model.CwChtbParams;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import javax.annotation.Resource;


import cn.hfatec.JsonResponse;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.constants.SysContant;
import cn.hfatec.freemarker.FreeMarkerUtil;
import cn.hfatec.shms.web.qz.qzActual.model.QzActualParams;
import cn.hfatec.shms.web.qz.qzActual.model.QzActual;
import cn.hfatec.shms.web.qz.qzActual.service.QzActualService;
import cn.hfatec.shms.base.ShmsBaseAction;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;



/**
 *
 * @author hfatec codegen
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Controller
@RequestMapping("/qz/qzActual")
public class QzActualAction extends ShmsBaseAction {

    //服务层
    @Resource(name = "QzActualService")
    private QzActualService qzActualService;


    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/list")
    public String list(QzActualParams qzActualParams, Page page, Model model) {
           page.setPageSize(1000);
        Table table = qzActualService.queryQzActualTable(qzActualParams, page);
        Calendar c = Calendar.getInstance();
        int week = c.get(Calendar.WEEK_OF_YEAR);
        model.addAttribute("weekNum", week);
        model.addAttribute("qzActualsTable", table);
        model.addAttribute("qzActualParams", qzActualParams);
        return "/qz/qzActual/list";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/ajaxList")
    @ResponseBody
    public String ajaxList(QzActualParams qzActualParams, Page page, Model model) {
        try {
            list(qzActualParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/qz/qzActual/table", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }






    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/lzlist")
    public String lzlist(QzActualParams qzActualParams, Page page, Model model) {
        page.setPageSize(1000);
        Table table = qzActualService.queryQzLzTable(qzActualParams, page);
        Calendar c = Calendar.getInstance();
        int week = c.get(Calendar.WEEK_OF_YEAR);
        model.addAttribute("weekNum", week);
        model.addAttribute("qzActualsTable", table);
        model.addAttribute("qzActualParams", qzActualParams);
        return "/qz/qzActual/lzlist";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/lzajaxList")
    @ResponseBody
    public String lzajaxList(QzActualParams qzActualParams, Page page, Model model) {
        try {
            lzlist(qzActualParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/qz/qzActual/lztable", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/yzlist")
    public String yzlist(QzActualParams qzActualParams, Page page, Model model) {
        page.setPageSize(1000);
        Table table = qzActualService.queryQzYzTable(qzActualParams, page);
        Calendar c = Calendar.getInstance();
        int week = c.get(Calendar.WEEK_OF_YEAR);
        model.addAttribute("weekNum", week);
        model.addAttribute("qzActualsTable", table);
        model.addAttribute("qzActualParams", qzActualParams);
        return "/qz/qzActual/yzlist";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/yzajaxList")
    @ResponseBody
    public String yzajaxList(QzActualParams qzActualParams, Page page, Model model) {
        try {
            yzlist(qzActualParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/qz/qzActual/yztable", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }

    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/hzlist")
    public String hzlist(QzActualParams qzActualParams, Page page, Model model) {
        page.setPageSize(1000);
        Table table = qzActualService.queryQzHzTable(qzActualParams, page);
        Calendar c = Calendar.getInstance();
        int week = c.get(Calendar.WEEK_OF_YEAR);
        model.addAttribute("weekNum", week);
        model.addAttribute("qzActualsTable", table);
        model.addAttribute("qzActualParams", qzActualParams);
        return "/qz/qzActual/hzlist";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/hzajaxList")
    @ResponseBody
    public String hzajaxList(QzActualParams qzActualParams, Page page, Model model) {
        try {
            hzlist(qzActualParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/qz/qzActual/hztable", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }


    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/wzlist")
    public String wzlist(QzActualParams qzActualParams, Page page, Model model) {
        page.setPageSize(1000);
        Table table = qzActualService.queryQzWzTable(qzActualParams, page);
        Calendar c = Calendar.getInstance();
        int week = c.get(Calendar.WEEK_OF_YEAR);
        model.addAttribute("weekNum", week);
        model.addAttribute("qzActualsTable", table);
        model.addAttribute("qzActualParams", qzActualParams);
        return "/qz/qzActual/wzlist";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/wzajaxList")
    @ResponseBody
    public String wzajaxList(QzActualParams qzActualParams, Page page, Model model) {
        try {
            wzlist(qzActualParams, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/qz/qzActual/wztable", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }
    /**
     * 导出excel
     */
    @RequestMapping("/export")
    @ResponseBody
    public String export(QzActualParams qzActualParams, HttpServletRequest request, HttpServletResponse response) {
        try {

           qzActualService.exportExcel(qzActualParams, request, response);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }
}
